package com.yuntongxun.ecdemo.voicechat.comman;

import com.google.gson.Gson;
import com.yuntongxun.ecdemo.voicechat.bean.TopicChatJson;
import com.yuntongxun.ecdemo.voicechat.util.CommonUtils;

/**
 * description：话题发送json
 * author：liucanwen on 16/12/15 11:11
 * email：liucanwen@baibu.la
 */
public class TopicContacts {

    /**
     * 生成话题聊天对话
     *
     * @return
     */
    public static String getTopicContact(String topicQuestion, String topicAnswer, int topicType) {

        TopicChatJson topicChatJson = new TopicChatJson();

        if(!CommonUtils.isEmpty(topicQuestion)) {
            topicChatJson.setQuestion(topicQuestion);
        }

        if(!CommonUtils.isEmpty(topicAnswer)){
            topicChatJson.setAnswer(topicAnswer);
        }

        topicChatJson.setType(topicType);

        String result = new Gson().toJson(topicChatJson);

        return result;

    }

    /**
     * 是否是话题json
     * @param json
     * @return
     */
    public static boolean isTopicJson(String json){

        if(!CommonUtils.isEmpty(json)){

            if(json.startsWith("[topic]")){
                return true;
            }
        }

        return false;

    }

    /**
     * 得到礼物json
     * @param json
     * @return
     */
    public static String getTopicJson(String json){

        if(!CommonUtils.isEmpty(json)){

            if(json.startsWith("[topic]")){

                String json2 = json.substring(json.indexOf("]") + 1, json.lastIndexOf("["));

                return json2;
            }
        }

        return "";

    }

}